/**
 * OSS is a Open Service Container which gives the leverage of building the Desktop and Web
 * Application. * Copyright (C) 2008-2009  Ponraj Sutanthiramani
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Or5e Open Source Community
 * 105, S.S Paradise Apartment, Munnireddy Layout, Horamavu, Banaswadi, Bangalore, India.
 */
package org.or5e.core;

import java.io.IOException;
import java.util.Properties;
import java.util.logging.Level;
import org.apache.log4j.Logger;

/**
 * @author Ponraj Suthanthiramani
 */
public abstract class BaseObject extends Object{
    public static String key = null;
    /**
     * This is the abstarct method which has to be implemented by all the API Sub classes other than Custom Thread and Custom Applet classes. This will return the Name of the class which will be used by the centerlized logging environment.
     * @return @see java.lang.String Name of the Sub Class
     */
    public abstract String getName() ;

    /**
     * No Arg Constructor
     */
    public BaseObject() {
        _logger = Logger.getLogger(getName());

    }

    /**
     * This is the method which will return the API Specific Properties to any of the API Consumer
     * @param key @see java.lang.String
     * @return value 
     */
    public static String getProperty(String key) {
        return (_props != null) ? _props.getProperty(key): null;
    }

    /**
     *
     * @param key
     * @param value
     */
    public static void setProperty(String key, String value) {
        if (_props != null) _props.setProperty(key, value);
    }

    protected final void info(Object message) {
        _logger.info(message);
    }
    protected final void debug(Object message) {
        _logger.debug(message);
    }
    protected final void warn(Object message) {
        _logger.warn(message);
    }
    protected final void error(Object message) {
        _logger.error(message);
    }
    public final void putMessage(String message) {
        _logger.info(message);
    }
    /**
     * Private logger which will be used to logging
     */
    private Logger _logger = null;

    /**
     * Private property file which will hold the property file data "OSS.properties"
     */
    private static Properties _props = null;

    static {
        _props = new Properties();
        try {
            _props.load(BaseObject.class.getResourceAsStream("OSS.properties"));
            System.setSecurityManager(new BaseSecurityManager());
            key = (_props.get("LICENSE") != null) ? _props.get("LICENSE").toString():"";
       }
        catch (IOException ex) {
            java.util.logging.Logger.getLogger(BaseObject.class.getName()).log(Level.SEVERE, null, ex);
            System.exit(1);
        }
    }
}